<HTML><HEAD><TITLE>listen(+Stream, +Queue)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Stream I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>listen(+Stream, +Queue)</H1>
Specifies how many connections are accepted for a socket and makes
connections available.


<DL>
<DT><EM>Stream</EM></DT>
<DD>Atom or integer.
</DD>
<DT><EM>Queue</EM></DT>
<DD>An integer.
</DD>
</DL>
<H2>Description</H2>
   listen/2 is a direct link to the listen(2) system call, available on
   Berkeley systems.  Stream must be a socket stream created with socket/3
   of the type stream.  Queue specifies the length of the connection queue,
   i.e.  how many connections are allowed for this socket.  After the call
   to listen/2, other processes can call connect/2 to connect with this
   socket, but the I/O is possible only after the server process creates
   the new socket using accept/3.

<P>
   Stream sockets are connected using the standard sequence, i.e.
   socket/3, bind/2, listen/2 and accept/3 on the server and socket/3 and
   connect/2 on the client.  After the sockets are connected, both
   processes can use them for reading and writing.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>listen(+, +) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Stream or Queue is not instantiated.
<DT><EM>(5) type error </EM>
<DD>Stream is instantiated, but not to an atom or an integer.
<DT><EM>(5) type error </EM>
<DD>Queue is instantiated but not to an integer.
<DT><EM>(170) system interface error </EM>
<DD>It was not possible to execute the system call.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      socket(internet, stream, s), bind(s, Addr), listen(s, 1).

Error:
      listen(s, N)                  (Error 4).
      listen(s, 1.0)                (Error 5).
      listen(null, 2)               (Error 170).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/iostream/socket-3.html">socket / 3</A>, <A HREF="../../kernel/iostream/bind-2.html">bind / 2</A>, <A HREF="../../kernel/iostream/accept-3.html">accept / 3</A>, <A HREF="../../kernel/iostream/connect-2.html">connect / 2</A>, <A HREF="../../kernel/iostream/new_socket_server-3.html">new_socket_server / 3</A>
</BODY></HTML>
